import requests
import json

def dataPOST():
   payload = {
      'adc': 300}
   heads = {'content-type':'application/josn'}
   response = requests.post('http://192.168.10.100:8000/data', json=payload, headers = heads)
   print(response.text)

def resPOST():
   payload = {
      'head': 1,
      'len': 2,
      'cmd': 4,
      'subCmd': 4,
      'data': [0, 1, 2]
   }
   print(json.dumps(payload))
   heads = {'content-type':'application/josn'}
   response = requests.post('http://192.168.10.100:8000/resRegister', json=payload, headers = heads)
   print(response.text)

def cmdGET():
   response = requests.get('http://192.168.10.100:8000/cmdRegister')
   try:
      request_data = json.loads(response.text)
      head = request_data.get('head')
      len = request_data.get('len')
      cmd = request_data.get('cmd')
      subCmd = request_data.get('subCmd')
      data = request_data.get('data')
      print(subCmd, type(subCmd))
   except:
      print("error")
      print(response.text)

if __name__ == '__main__':
   # cmdGET()
   dataPOST()
   # resPOST()